using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using PccCommonForC;

public partial class Manager_Menu_SortMenu : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["AdminUserID"] == null)
        {
            Response.Write("<script language=javascript>alert('Time is out.');window.open('../Default.aspx','_top');</script>");
            return;
        }
        Ajax.Utility.RegisterTypeForAjax(typeof(Manager_Menu_SortMenu));
        if (!IsPostBack)
            Create_SeqPortalAp(lbPortalAp_seq);
    }
    private DataSet GetData()
    {
        PccMsg msg = new PccMsg();
        string Groupid = "0";
        string KindNo = "";
        if (Request.QueryString["KindNo"] != "" && Request.QueryString["KindNo"] != null)
            KindNo = Request.QueryString["KindNo"];

        if (Request.QueryString["Groupid"] != "" && Request.QueryString["Groupid"] != null)
        {
          
            Groupid = Request.QueryString["Groupid"];
        }
   
        msg.CreateFirstNode("LevelMenuID", Groupid);
        msg.CreateFirstNode("KindNo", KindNo);

        clsWebShop cls = new clsWebShop();
        DataSet ds = null;
        ds = cls.Get_MenuByCondition(msg.GetXmlStr);
        return ds;
      

    }
    [Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)]
    public string UpdTurnSort(string MenuID1, string MenuID2)
    {
        clsWebShop cls = new clsWebShop();
        PccMsg msg = new PccMsg();
        msg.CreateFirstNode("MenuID1", MenuID1);
        msg.CreateFirstNode("MenuID2", MenuID2);
        string strReturn = cls.Upd_SeqMenu(msg.GetXmlStr.ToString());
        return " ";
    }

    public void Create_SeqPortalAp(ListBox lb)
    {
        DataTable dt = GetData().Tables[0];

        lb.Items.Clear();

        int iCount = 1;

        foreach (DataRow dr in dt.Rows)
        {
            ListItem item = new ListItem();
            item.Text = iCount.ToString() + "/ " + dr["MenuName"].ToString();
            item.Value = dr["MenuID"].ToString();

            lb.Items.Add(item);
            iCount++;
        }
    }

    string GetControlRenderString(System.Web.UI.Control ctrl)
    {
        string ret = "";
        System.IO.StringWriter stringWriter = new System.IO.StringWriter();
        HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
        try
        {
            HtmlForm frm = new HtmlForm();
            frm.Controls.Add(ctrl);
            ctrl.RenderControl(htmlWriter);
            ret = stringWriter.ToString().Replace("\n", "").Replace("\t", "").Replace("\r", "");
        }
        catch (Exception e)
        {
            ret = e.Message;
        }
        return ret;
    }
}
